package com.hckjsec.cloud.controller;

import java.util.ArrayList;
import java.util.List;

import com.hckjsec.cloud.service.WxSendTplMessageService;
import com.hckjsec.common.utils.DateUtils;
import com.hckjsec.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hckjsec.common.annotation.Log;
import com.hckjsec.common.core.controller.BaseController;
import com.hckjsec.common.core.domain.AjaxResult;
import com.hckjsec.common.enums.BusinessType;
import com.hckjsec.cloud.domain.AppletsBusinessConsulting;
import com.hckjsec.cloud.service.IAppletsBusinessConsultingService;
import com.hckjsec.common.utils.poi.ExcelUtil;
import com.hckjsec.common.core.page.TableDataInfo;

/**
 * 申办信息咨询Controller
 * 
 * @author cyt
 * @date 2021-10-26
 */
@RestController
@RequestMapping("/system/consulting")
public class AppletsBusinessConsultingController extends BaseController
{
    @Autowired
    private IAppletsBusinessConsultingService appletsBusinessConsultingService;

    @Autowired
    private WxSendTplMessageService wxSendTplMessageService;
    /**
     * 查询申办信息咨询列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AppletsBusinessConsulting appletsBusinessConsulting)
    {
        startPage();
        if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            appletsBusinessConsulting.setDeptId(SecurityUtils.getDeptId());
        }
        List<AppletsBusinessConsulting> list = appletsBusinessConsultingService.selectAppletsBusinessConsultingList(appletsBusinessConsulting);
        return getDataTable(list);
    }

    /**
     * 导出申办信息咨询列表
     */
    @Log(title = "申办信息咨询", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AppletsBusinessConsulting appletsBusinessConsulting)
    {
        if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            appletsBusinessConsulting.setDeptId(SecurityUtils.getDeptId());
        }
        List<AppletsBusinessConsulting> list = appletsBusinessConsultingService.selectAppletsBusinessConsultingList(appletsBusinessConsulting);
        ExcelUtil<AppletsBusinessConsulting> util = new ExcelUtil<AppletsBusinessConsulting>(AppletsBusinessConsulting.class);
        return util.exportExcel(list, "consulting");
    }

    /**
     * 获取申办信息咨询详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(appletsBusinessConsultingService.selectAppletsBusinessConsultingById(id));
    }

    /**
     * 新增申办信息咨询
     */
    @Log(title = "申办信息咨询", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppletsBusinessConsulting appletsBusinessConsulting)
    {
        return toAjax(appletsBusinessConsultingService.insertAppletsBusinessConsulting(appletsBusinessConsulting));
    }

    /**
     * 修改申办信息咨询
     */
    @Log(title = "申办信息咨询", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppletsBusinessConsulting appletsBusinessConsulting)
    {
        appletsBusinessConsulting.setState("1");
        appletsBusinessConsulting.setReviewer(SecurityUtils.getUsername());
        appletsBusinessConsulting.setReviewerdatetime(DateUtils.parseDate(DateUtils.getTime()));
        int rows = appletsBusinessConsultingService.updateAppletsBusinessConsulting(appletsBusinessConsulting);
        if (rows > 0){
            List<String> phonelist = new ArrayList<String>();
            phonelist.add("+86"+appletsBusinessConsulting.getPhone());
            wxSendTplMessageService.sendAddOrder(phonelist, appletsBusinessConsulting.getConfigId(),"10","","","");
        }
        return toAjax(rows);
    }

    /**
     * 删除申办信息咨询
     */
    @Log(title = "申办信息咨询", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(appletsBusinessConsultingService.deleteAppletsBusinessConsultingByIds(ids));
    }
}
